<!doctype html>
<html>

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
  <title>地图初始IP城市定位</title>
  <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
  <style type="text/css">
    html,
    body,
    #container {
      height: 100%;
    }

    .info {
      width: 20rem;
    }
  </style>
</head>

<body>
  <div id="container"></div>
  <div class="info">
    <p>在初始化地图时，如果center属性缺省，地图默认定位到用户所在城市的中心</p>
    <hr>
    <p id='adcode'></p>
  </div>
  <script type="text/javascript">
    window._AMapSecurityConfig = {
      securityJsCode: 'eb6e52028dec255cf15d178135789d25',
    }
  </script>
  <script type="text/javascript" src="https://webapi.amap.com/maps?v=2.0&key=f8bb2d2568a4e14a23d16b24c5ed1772"></script>
  <script type="text/javascript">
    //初始化地图时，若center属性缺省，地图默认定位到用户所在城市的中心
    var map = new AMap.Map('container', {
      zoom: 20,
    });
    document.getElementById('adcode').innerHTML = '当前城市adcode：' + map.getAdcode() + '<br>' +
      '当前中心点：' + map.getCenter()
  </script>
</body>

</html>